import { MenuState, MenuStateNoChildren, SelectMenuAllParams } from '@/interfaces/api/menu'
import { ResProps } from '@/interfaces/request'
import request from '@/utils/request'
import { AxiosPromise } from 'axios'

/**
 * @description: 根据用户id获取要渲染的菜单
 */
export const getMenuListByUserId = ({
  userId,
}: {
  userId: number | string
}): AxiosPromise<ResProps<MenuState>> => {
  return request({
    url: '/menu/list',
    method: 'GET',
    params: {
      userId,
    },
  })
}

/**
 * @description: 添加菜单
 */
export const addMenuApi = (data: MenuStateNoChildren): AxiosPromise<ResProps<null>> => {
  return request({
    url: '/menu/add',
    method: 'post',
    data,
  })
}

/**
 * @description: 更新菜单
 */
export const updateMenuApi = (data: MenuStateNoChildren): AxiosPromise<ResProps<null>> => {
  return request({
    url: '/menu/update',
    method: 'post',
    data,
  })
}

/**
 * @description: 根据菜单id查询菜单具体信息
 */
export const selectOneMenuByIdApi = (
  id: string | number
): AxiosPromise<ResProps<MenuStateNoChildren>> => {
  return request({
    url: '/menu/selectOne',
    method: 'get',
    params: {
      id,
    },
  })
}

/**
 * @description: 根据菜单id查询菜单具体信息
 */
export const selectMenuAllApi = (
  data: SelectMenuAllParams
): AxiosPromise<ResProps<MenuStateNoChildren[]>> => {
  return request({
    url: '/menu/all',
    method: 'get',
    params: data,
  })
}

/**
 * @description: 根据菜单id查询菜单具体信息
 */
export const selectSelectMenuAllApi = (): AxiosPromise<ResProps<MenuStateNoChildren[]>> => {
  return request({
    url: '/menu/selectSelect',
    method: 'get',
  })
}

/**
 * @description: 删除菜单
 * @param {}
 * @return {}
 */
export const deleteMenuApi = ({ id }: { id: string | number }): AxiosPromise<ResProps<null>> => {
  return request({
    url: '/menu/delete?id=' + id,
    method: 'post',
  })
}
